<%--                                                                       --%>
<%-- Copyright (c) 2001-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>
<%--                                                                       --%>


<%@ page language="java" %>
<%@ page import = "java.util.*" %>
<%@ page import = "org.apache.struts.util.RequestUtils" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>

<bean:define id="micrositeNaviInfoParams" name="micrositeNaviInfoView" property="urlParams" scope="request" />
             
<script language="javascript" src="<%= request.getContextPath() %>/cs/js/date.js" type="text/javascript">
</script>

<script language="javascript" src="<%= request.getContextPath() %>/cs/js/stringFunc.js" type="text/javascript">
</script>

<script language="javascript">
function openwin(file) {
  var win = window.open(file , "NewWindow", 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=450,height=338');
  win.focus();
}

function onFileInputFocus()
{
  return theForm.attOriginalFileName.focus();
}

<% 
  String nextAction = "/cs/meetingAttachmentAdd.do";
  String nextPage = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           nextAction,
                                           null,
                                           null,
                                           false);
  String relativeDir = "/";
  // + csMeetingEditForm.getServiceName() 
   //                        + "/microsite/" 
    //                       + csMeetingEditForm.getMicrositeId(); 

%>

function onClickDeleteAttachment(index, id) {
  if (confirm("<bean:message key="cs.confirm.delete.attachment"/>")) {
    var theForm = document.csMeetingEditForm;
    theForm.action = '<html:rewrite page="/cs/meetingAttachmentRemove.do"/>';
    theForm.encoding = "application/x-www-form-urlencoded";
    theForm.method = "post";
    theForm.deleteAttIndex.value = index;
    theForm.deleteAttId.value = id;
    theForm.submit();
  }
  return false;
}

function onClickSave(theForm) {
  if (validateForm(theForm)) {
    setEndDateToStartDate(theForm, "start", "end");
    theForm.notify.value = "false";
    theForm.submit();
  }
  return false;
}

function onClickSaveAndNotify(theForm) {
  if (validateForm(theForm)) {
    setEndDateToStartDate(theForm, "start", "end");
    theForm.notify.value = "true";
    theForm.submit();
  }
  return false;
}

function removeRelatedItem(OID, contentType) {
  var theForm = document.csMeetingEditForm;
  theForm.action = '<html:rewrite page="/cs/meetingRelatedItemRemove.do"/>';
  theForm.removeRelatedId.value = OID;
  theForm.removeRelatedContentType.value = contentType;
  theForm.parentContentType.value = '328'; // Meeting
  theForm.encoding = "application/x-www-form-urlencoded";
  theForm.method = "post";
  theForm.submit();
}

<%--
function onClickBrowseRelatable() {
  var theForm = document.csMeetingEditForm;
  if(theForm.selectedRelatableType.value < 0) return;
  var redirectUrl;
  switch(theForm.selectedRelatableType.value) {
  // Messages
  case "25":
    redirectUrl = '<html:rewrite page="/cs/relatedMessage.do" name="micrositeNaviInfoView" paramId="contentName" paramName="csMeetingEditForm" paramProperty="name"/>';
    break;
  // documents
  case "322":
   // redirectUrl = '<html:rewrite page="/cs/relatedDocument.do" name="micrositeNaviInfoView"  paramId="contentName" paramName="csMeetingEditForm" paramProperty="name"/>';
    break;
  default:
    //redirectUrl = '<html:rewrite page="/cs/categoryBrowse.do" name="micrositeNaviInfoView"  paramId="contentName" paramName="csMeetingEditForm" paramProperty="name" />';
    if(redirectUrl.indexOf("?") > 0) {
      redirectUrl += '&amp;contentTypeId=' + theForm.selectedRelatableType.value;
    }
    else {
      redirectUrl += '?contentTypeId=' + theForm.selectedRelatableType.value;
    }

  }
  // The following two lines are necessary for netscape to correctly send the
  // query string
  var re = new RegExp('&amp;','gi');
  var newRedirectUrl = redirectUrl.replace(re,"&");

  var win = window.open(newRedirectUrl,'addRelatedItem', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=700,height=500');
  win.focus();
}

// Load the related items chosen in the pop-up window
function loadRelatedItems(OIDs, contentType) {
  var theForm = document.csMeetingEditForm;
  theForm.relatedItems.value = OIDs;
  theForm.relatedItemsContentType.value = contentType;
  theForm.action = '<html:rewrite page="/cs/meetingAddRelated.do"/>'
  theForm.encoding = "application/x-www-form-urlencoded";
  theForm.method = "post";
  theForm.submit();
}

--%>

function onClickDeleteMeeting(theForm, url) {
   if (confirm("<bean:message key="cs.confirm.delete.meeting"/>")) {
     theForm.action = url;
     theForm.submit();
   }
   return false;
}

//Set the end year, month, day the same as the start year, month, day.
function setEndDateToStartDate(thisForm, startDateFieldPrefix, endDateFieldPrefix) {
  var startYearSelectName  = startDateFieldPrefix + ".year";
  var startMonthSelectName = startDateFieldPrefix + ".month";
  var startDaySelectName   = startDateFieldPrefix + ".day";
  var endYearSelectName  = endDateFieldPrefix + ".year";
  var endMonthSelectName = endDateFieldPrefix + ".month";
  var endDaySelectName   = endDateFieldPrefix + ".day";

  var elements = thisForm.elements;
  var numElements = elements.length;

  var startYearSelectValue;
  var startMonthSelectValue;
  var startDaySelectValue;

  var count;
  //Gets selected start year, month and day first.
  for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
    var oneElement = elements[elementIndex];
    var elementName = oneElement.name;

    if (elementName == startYearSelectName) {
      startYearSelectValue = oneElement.options[oneElement.selectedIndex].value;
      count++;
    }
    else if (elementName == startMonthSelectName) {
      startMonthSelectValue = oneElement.options[oneElement.selectedIndex].value;
      count++;
    }
    else if (elementName == startDaySelectName) {
      startDaySelectValue = oneElement.options[oneElement.selectedIndex].value;
      count++;
    }
    if (count == 3) break;
  }
  //reset counter to 0.
  count = 0;
  for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
    var oneElement = elements[elementIndex];
    var elementName = oneElement.name;

    if (elementName == endYearSelectName) {
      oneElement.value = startYearSelectValue;
      count++;
    }
    else if (elementName == endMonthSelectName) {
      oneElement.value = startMonthSelectValue;
      count++;
    }
    else if (elementName == endDaySelectName) {
      oneElement.value = startDaySelectValue;
      count++;
    }
    if (count == 3) break;
  }

}
//
// Returns the user's selection for the end time.
//
// Returns a JavaScript Date object for the selected date/time
// or null if the selection is not valid.
//
function getEndDate(start, thisForm, name)
{
  var yearSelectName  = start + ".year";
  var monthSelectName = start + ".month";
  var daySelectName   = start + ".day";
  var hourSelectName  = name + ".hour";
  var minuteSelectName = name + ".minute";
  var indSelectName   = name + ".ind";

  var elements = thisForm.elements;
  var numElements = elements.length;

  var yearSelect;
  var monthSelect;
  var daySelect;
  var hourSelect;
  var minuteSelect;
  var indSelect = null;

  var count = 0;

  for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
    var elementName = elements[elementIndex].name;
    if (elementName == yearSelectName) {
      yearSelect = elements[elementIndex];
      count++;
    }
    else if (elementName == monthSelectName) {
      monthSelect = elements[elementIndex];
      count++;
    }
    else if (elementName == daySelectName) {
      daySelect = elements[elementIndex];
      count++;
    }
    else if (elementName == hourSelectName) {
      hourSelect = elements[elementIndex];
      count++;
    }
    else if (elementName == minuteSelectName) {
      minuteSelect = elements[elementIndex];
      count++;
    }
    else if (elementName == indSelectName) {
      indSelect = elements[elementIndex];
      count++;
    }

    if (count == 6) break;
  }

  var yri = yearSelect.selectedIndex;
  var mni = monthSelect.selectedIndex;
  var dyi = daySelect.selectedIndex;

  var yr = yearSelect.options[yri].value;
  var mn = monthSelect.options[mni].value;
  var dy = daySelect.options[dyi].value;

  if (yr == -1 || mn == -1 || dy == -1)
    return null;

  if (!isValidDate(yr, mn, dy))
    return null;

  var hhi = hourSelect.selectedIndex;
  var mmi = minuteSelect.selectedIndex;
  var hh = hourSelect.options[hhi].value;
  var mm = minuteSelect.options[mmi].value;
  var ss = 0;

  //
  // if 12-hour format, check the AM/PM indicator
  //

  if (null != indSelect && indSelect.type == 'select-one') {
    var indi = indSelect.selectedIndex;
    var ind = indSelect.options[indi].value;

    if (hh == -1 || mm == -1 || ind == -1) {
      return null;
    }
    if (ind == 1) {
      hh = parseInt(hh);
      hh += 12;
    }
  }
  if (hh == -1 || mm == -1) {
    return null;
  }

  var date = new Date(yr, mn, dy, hh, mm, ss);

  return date;
}


//
// Validate the user's entries.
//
function validateForm(theForm)
{
   var meetingName = stringTrim(theForm.name.value);

   if (meetingName == "")
   {
      alert("<bean:message key="cs.error.meeting.name"/>");
      return false;
   }

   var meetingDesc = stringTrim(theForm.description.value);
   if (meetingDesc.length > 2000) 
   {
      alert("<bean:message key="cs.error.meeting.description"/>");
      return false;
   }

   var agenda = stringTrim(theForm.agenda.value);
   if (agenda.length > 2000) 
   {
      alert("<bean:message key="cs.error.meeting.agenda"/>");
      return false;
   }

   <logic:notEqual name="csMeetingEditForm" property="meetingId" value="0">

   var meetingMinutes = stringTrim(theForm.minutes.value);
   if (meetingMinutes.length > 2000) 
   {
      alert("<bean:message key="cs.error.meeting.minutes"/>");
      return false;
   }
   </logic:notEqual>

   var groupIndex = theForm.groupIds.selectedIndex;

   if (groupIndex == -1)
   {
      alert("<bean:message key="cs.error.meeting.read.group"/>");
      return false;  
   }

   var selectedOwner = document.csMeetingEditForm.ownerId.value;
   if (selectedOwner == -1 || selectedOwner == 0)
   {
      alert("<bean:message key="cs.error.meeting.owner"/>");
      return false;  
   }

   var startDate = getDate("csMeetingEditForm", "start");

   if (startDate == null)
   {
      alert("<bean:message key="cs.error.meeting.startDate"/>");
      return false;
   }

   var endDate = getEndDate("start", theForm, "end");

   if (endDate == null)
   {
      alert("<bean:message key="cs.error.meeting.endDate"/>");
      return false;
   }

   if (startDate.getTime() > endDate.getTime())
   {
      alert("<bean:message key="cs.error.meeting.endTimeBeforeStartTime"/>");
      return false;
   }

   var attachName = stringTrim(theForm.attName.value);
   var attachFile = stringTrim(theForm.attOriginalFileName.value);

   if (attachName != "" || attachFile != "")
   {
     alert('<bean:message key="cs.error.attachment.add.more"/>');
     return false;
   }

   var locationFld=stringTrim(theForm.location.value);
   if (locationFld == "")
   {
      alert("<bean:message key="cs.error.meeting.location"/>");
      return false;
   }

   return true;
}

function 
arrayContainsItem(array, item)
{
   var len_array = array.length;
   var i_array;

   for (i_array = 0; i_array < len_array; i_array++)
   {
      if (array[i_array] == item)
      {
         return true;
      }
   }

   return false;
}


//
// Create a dummy (timestamp) attribute to get around an IE cache problem.
//
function getTimeStamp() {
   var now = new Date;
   var timestamp = '' + now.getYear() + now.getMonth() + now.getDate() + now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds();
   return timestamp;
}   


function selectOwnerPopup(theForm) {
  var groupIndex = document.csMeetingEditForm.groupIds.selectedIndex;

  if (groupIndex == -1) {
    alert("<bean:message key="cs.error.meeting.read.group"/>");
    return false;	
  }   

  var popupURL = '<html:rewrite page="/cs/contentSelectOwner.do" name="micrositeNaviInfoParams" />';
  var timestamp = getTimeStamp();
  popupURL += '&timestamp=' + timestamp;

  var win = window.open('', "ContentSelectOwner", "width=500,height=400,scrollbars=yes,resizable=yes");
  if ( win != null) {
    if( win.opener == null) {
      win.opener = self;
    }
  }
  win.focus();
  // save the current form setting so that it can be restored later
  var oldAction = theForm.action;
  var oldTarget = theForm.target;
  // submit the form to the popup so that we can pass the groupIds to the popup
  theForm.action = popupURL;
  theForm.target = "ContentSelectOwner";   
  theForm.submit();
  theForm.action = oldAction;
  theForm.target = oldTarget;
}

function setOwner(selectedOwnerId, selectedOwnerName) {
  document.csMeetingEditForm.ownerId.value = selectedOwnerId;
  document.csMeetingEditForm.ownerName.value = selectedOwnerName;

}

function resetOwner(selectedOwnerId, selectedOwnerName) {
  document.csMeetingEditForm.ownerId.value = -1;
  document.csMeetingEditForm.ownerName.value = "";

}


</script>

<!-- Zone 5 starts here.  -->
      
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
       summary="content area">
  <tr>
    <td valign="top">
    
    <!--start microsite logo and name here-->
      <div class="pageTitle">
        <%@ include file="/cs/microsite/micrositeNaviInfo.jsp" %>
      </div> 
    <!--end microsite logo and name here-->
    
    <!--  BEGIN form { meeting } ----------------------------- -->

    <html:form action="/cs/meetingSave.do">
    <bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>
    <html:hidden property="sequenceKey"/>
    <input type="hidden" name="notify" value="false"> <%-- Its value will be assigned by JavaScript. --%>
    <input type="hidden" name="parentContentType" value="328"/>
  
    <!--start title bar here-->
    <div class="pageSubtitle">
      <span class="left">
        <logic:equal name="csMeetingEditForm" property="meetingId" value="0">
          <bean:message key="cs.meeting.new"/>
        </logic:equal>
        <logic:notEqual name="csMeetingEditForm" property="meetingId" value="0">
         <bean:define id="meetingEditName" name="meetingEditView" property="persistentName"/>      
	           <%String meetEditName = meetingEditName.toString();%>
            <bean:message key="cs.edit" arg0="<%=meetEditName%>"/> 
        </logic:notEqual>
      </span>
      <span class="right">
	&nbsp;
      </span>
    </div> 
    <!--end title bar here--> 
    
    <div class="blockWrap">
    
    <!-- start Page Instructions -->
    <div class="pageInstructions">
      <logic:equal name="csMeetingEditForm" property="meetingId" value="0">
          <bean:message key="cs.meeting.new.note"/>
      </logic:equal>
      <logic:notEqual name="csMeetingEditForm" property="meetingId" value="0">
          <bean:message key="cs.meeting.edit.note"/>
      </logic:notEqual>
    </div>
    <!-- End Page Instructions -->
        
    <!--start main content area here-->
    <table class="labelForm" width="100%" border="0" cellspacing="0" 
           cellpadding="0" summary="Meeting Information">
             
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.name"/>*: </td>
        <td width="80%" class="labelField"> 
          <html:text property="name" size="31" maxlength="80"/>
        </td>
      </tr>
      <tr> 
        <td nowrap width="20%" class="label"> 
          <bean:message key="cs.description"/>: 
        </td>
        <td width="80%" class="labelField"> 
           <html:textarea property="description" cols="30" rows="4"/>
        </td>
      </tr>
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.meeting.agenda"/>:</td>
        <td width="80%" class="labelField"> 
          <html:textarea property="agenda" cols="45" rows="4"/> 
        </td>
      </tr>
      <logic:notEqual name="csMeetingEditForm" property="meetingId" value="0">
        <tr> 
          <td nowrap width="20%" class="label"><bean:message key="cs.meeting.minutes"/>:</td>
          <td width="80%" class="labelField"> 
            <html:textarea property="minutes" cols="45" rows="4"/>
          </td>
        </tr>
      </logic:notEqual>
      <logic:equal name="micrositeNaviInfoView" property="micrositeTemplatePhaseFlag" value="true">
      <bean:define id="allPhasesList" name="meetingEditView" property="allPhasesList" />
        <tr> 
          <td nowrap width="20%" class="label"><bean:message key="cs.phase"/>*:</td>
          <td width="80%" nowrap class="labelField"> 
            <html:select property="newPhaseId" size="1">
              <html:options name="meetingEditView" collection="allPhasesList" property="id" labelProperty="name" />
            </html:select>
          </td>
        </tr>
      </logic:equal>
      <logic:equal name="micrositeNaviInfoView" property="micrositeTemplatePhaseFlag" value="false">
      	<html:hidden property="phaseId"/>
      </logic:equal>
      <tr> 
        <td width="20%" class="label" valign="top"><bean:message key="cs.read.access.groups"/>*:<br>
        </td>
        <td nowrap width="80%" class="labelField">
          <html:select property="groupIds" size="4" multiple="true" onchange="resetOwner()">
             <html:optionsCollection name="meetingEditView" property="availableGroups"/>
          </html:select>
        </td>
      </tr>
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.owner"/>*:</td>
        <td nowrap width="80%" class="labelField"> 
          <html:text name="csMeetingEditForm" property="ownerName" readonly="true"/>
          <input type="hidden" name="ownerId" value=<bean:write name="csMeetingEditForm" property="ownerId"/> >
          <html:button property="selectOwner" onclick="selectOwnerPopup(this.form)" styleClass="inputButton">
            <bean:message key="cs.button.select.owner"/>
          </html:button>
        </td>
      </tr>
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.date"/>*:</td>
        <td nowrap width="80%" class="labelField"> 
          <bvhtml:date name="csMeetingEditForm" property="start"/>
          <a href="JavaScript:datePopup('<html:rewrite page="/cs/calendar.do"/>', 'csMeetingEditForm','start')"><img src="<%= request.getContextPath() %>/cs/images/icons/calendar.gif" border="0" align="absmiddle"/></a>
        </td>
      </tr>
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.time"/>*:</td>
        <td nowrap width="80%" class="labelField"> 
      	  <bvhtml:time name="csMeetingEditForm" property="start"/>
          &nbsp;-&nbsp; 
      	  <bvhtml:time name="csMeetingEditForm" property="end"/>
      	  <input type=hidden name="end.year">
      	  <input type=hidden name="end.month">
      	  <input type=hidden name="end.day">
        </td>  
      </tr>
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.meeting.location"/>*:</td>
        <td nowrap width="80%" class="labelField"> 
          <html:text property="location" size="31" maxlength="80"/>
        </td>
      </tr>
    </table>
    <% // Need to define the attachment form bean for the included JSP %>
   <!-- Start Display attachment. -->
  
      <script language="JavaScript">
      <%-- nextPage variable will be used by attachmentEdit.jsp --%>
      
      var nextPage = '<html:rewrite page="/cs/meetingAttachmentAdd.do"/>';
      var attachmentDeleteAction = '<html:rewrite page="/cs/meetingAttachmentDelete.do" />';

      <logic:equal name="csMeetingEditForm" property="meetingId" value="0">
        var nextActionAfterCancel = '/cs/meetingList.do';
        var nextActionAfterReset = '/cs/meetingNew.do';
      </logic:equal>
      <logic:notEqual name="csMeetingEditForm" property="meetingId" value="0">
        var nextActionAfterCancel = '/cs/meetingView.do';
        var nextActionAfterReset = '/cs/meetingEdit.do';
      </logic:notEqual>
    </script>
    
    <bean:define id="formBeanUsed" name="csMeetingEditForm" toScope="request" />
    <%@ include file="/cs/microsite/attachment/attachmentEdit.jsp" %>
    <!-- end of attachments section -->

    
    
    <!--start cancel, reset, save bar area here-->

    <div class="pageButtonWrap" align="right">
      <html:button styleClass="pageButton" property="resetBtn" 
                  titleKey="button.reset" onclick="return resetAttachment(this.form)">
          <bean:message key="button.reset"/>
      </html:button>  
	&nbsp;&nbsp;
      <html:button styleClass="pageButton" property="cancelBtn" 
             titleKey="button.cancel" onclick="return cancelClearAttachment(this.form)">
        <bean:message key="button.cancel"/>
      </html:button>
             
      <html:button styleClass="pageButton" property="saveBtn" 
             titleKey="button.save" onclick="return onClickSave(this.form)">
        <bean:message key="button.save"/>
      </html:button>
      
      <html:button styleClass="pageButton" property="saveNotifyBtn" 
             titleKey="button.savenotify" onclick="onClickSaveAndNotify(this.form)">
        <bean:message key="button.savenotify"/>
      </html:button>
              
    </div>     
    <!--end cancel, reset, save bar area here-->
    </html:form>
    
    </div>
    
    </td>
  </tr>
</table>
<!--end zone 5 content here --> 


